package com.ellwood.copyright.modules.softConf.service.impl;

import com.alibaba.druid.pool.DruidDataSource;
import com.ellwood.copyright.common.core.annotation.Master;
import com.ellwood.copyright.common.core.enums.HttpCodeEnum;
import com.ellwood.copyright.infrastructure.softConf.dto.TableInfoDTO;
import com.ellwood.copyright.modules.softConf.logic.TableValidateLogic;
import com.ellwood.copyright.modules.softConf.service.TableService;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;

/**
 * @ProjectName: ell-copyright-pro
 * @PackageName: com.ellwood.copyright.modules.softConf.service.impl
 * @ClassName: TableServiceImpl
 * @Description: // TODO
 * @Author: Ellwood
 * @CreateDate: 2024/11/20 - 22:47
 * @Version: V1.0.0
 */
@Slf4j
@Master
@Service
@AllArgsConstructor
public class TableServiceImpl implements TableService {

    private final JdbcTemplate jdbcTemplate;

    private final DataSource dataSource;

    @Override
    public void executeSQL(TableInfoDTO tableInfoDTO) {
        // 使用 JdbcTemplate 的 execute 方法来执行 SQL 语句
        try{
            TableValidateLogic.generateTable(tableInfoDTO,dataSource);
        }catch (Exception e){
            log.error(e.getMessage());
            throw new RuntimeException(HttpCodeEnum.SQL_EXECUTE_ERROR.getMessage());
        }
    }

}
